# -*- coding: utf-8 -*-
import os, json

from url_dir.url import default_url

ACLOUD_URL = 'https://200.201.22.199:443'
admin123 = '76f4dd19fcd75738937a63446deae49be7cb61f8e366c1adf5a7a8955ec86be09dadb6569653c0c4b955ff7ee999516b96baf909de3a07833c5817600cb1c072081cc9244f11f0d16e3a39ae153d85ab9fdd6c89d7b0a20a18cef32c035ddcd347bbcec463d97d5591bfc10c9ad698be2b4a719287ece430ee103043cf84eff72ab7fb46be89c7bf6c529825533383c7cd5b9dc3b1e0229449c7ee89cae453aad933f3c912e0d28b94c821bb481e4ef8267a19c2bae6ac5173d2b967c761815e8bc00d4161be0571ca9fab2101b1aee9791b8de6caa29478e89593ce56d473fdd36eb5f617c11d2ce0b6d819bca55ce0504d9ad93952ea9be82cc973bdce3f79'

JSON_DIR = './js/'
ROUTE_PATH = './route/route.json'
ACLOUD_LOGIN = ACLOUD_URL + '/vapi/extjs/access/ticket'
version_url = '/vapi/json/cluster/api_version'

default_data = {
    'data': {
    },
    'success': 1
}

POST_LOGIN_DATA = {
    'username': 'admin',
    'password': admin123,
    'hardware': '',
    'certinfo': '',
}


def create_route_json():
    if not os.path.exists(ROUTE_PATH):
        with open(ROUTE_PATH, 'w') as f:
            json.dump({}, f)


def wirte_js_route(data, path, status_code):
    """
    :param data: 采集到的json数据
    :param json_name: js文件名
    :param path: route的键名
    :return: 生成js文件夹的json文件，将映射写入routr.json
    """
    json_name = path.replace('/', '_') + '.json'
    write_dir = JSON_DIR + json_name
    with open(write_dir, "w") as f:
        json.dump(data, f)
    with open(ROUTE_PATH, 'r+') as f:
        route_json = json.load(f)
        route_json[path] = [json_name, status_code]
        f.seek(0)  # 读了文件之后光标是在最后，需要将文件光标置于最前方
        json.dump(route_json, f)


def create_defaut_url():
    for url in default_url:
        data = json.dumps(default_url[url])
        wirte_js_route(data, url, 200)


class config():
    DEBUG = True
